import { Component, OnInit } from '@angular/core';
import { Router,RouteParams } from '@angular/router-deprecated';
import { Param } from '../model/param.model';
import { Api } from '../model/api.model';
import { Proj } from '../model/proj.model';
import { Group } from '../model/group.model';
import { CodeFormatterDirective } from './directives/codeformater.directive';
import { GlobalService } from '../services/global.service';
import {BaseRequestOptions,Http,Response, HTTP_PROVIDERS,Headers} from '@angular/http';
import { ProjService } from '../services/proj.service';
import { GroupService } from '../services/group.service';
import { ApiService } from '../services/api.service';

@Component({
  selector: 'api-component',
  viewProviders: [HTTP_PROVIDERS,ApiService,GroupService],
  templateUrl: 'app/api/tpl/api.show.html',
  directives:[ApiShowComponent,CodeFormatterDirective]
})
export class ApiShowComponent implements OnInit {
  apiData:Api = new Api();
  proj:Proj = new Proj();
  group:Group = new Group();
  allGroups:Group[] = [];
  allApis:Api[]=[];
  allDocsByProject:any={};
  constructor(private router: Router,routeParams:RouteParams,private apiService:ApiService,private groupService: GroupService) {
    this.apiService.authInit(router,()=>{
      var apiId = routeParams.get("apiId")
      this.apiService.get(apiId) && this.apiService.get(apiId).subscribe(data=>{
        this.apiData = data.json()
        this.proj = <any>this.apiData['project'];
        this.group = <any>this.apiData['group'];
        var p = this.apiService.getApisByProj(this.proj._id) ;
        if(p)
        {
          p.subscribe(data=>{
            this.allDocsByProject = data.json();
          })
        }
      });
    });
  }

  ngOnInit() {

  }

  showApi(apiId)
  {
    this.router.navigate(['ShowApi',{apiId:apiId}]);
  }

  showApis(groupId)
  {
    this.router.navigate(['Apis',{groupId:groupId,projId:this.proj._id}]);
  }

}

/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
